package com.net.xpay.core.enums;

import com.net.common.enums.base.IntEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Getter
@AllArgsConstructor
public enum PayeeType implements IntEnum<PayeeType> {
    ALIPAY(1, "支付宝"),
    BANK(2, "银行卡");

    private int value;

    private String desc;

    private static final Map<Integer, PayeeType> TYPES = new HashMap<>();

    static {
        for (PayeeType type : PayeeType.values()) {
            TYPES.put(type.getValue(), type);
        }
    }

    public static PayeeType get(Integer type) {
        if (type == null) {
            return null;
        }
        return TYPES.get(type);
    }


    public static boolean isValid(PayeeType type) {
        if (type == null) {
            return false;
        }
        return Arrays.stream(PayeeType.values()).anyMatch(t -> t == type);
    }
}
